(function(window){
const cateBox = document.querySelector('#product > .nevList');
const message = document.querySelector('#message');



getProduct()
function getProduct(){
    ajax({
        url:'http://chst.vip:1234/api/getbaicaijiatitle',
        success(res){
            res = res.result
            binlist(res)
        }
    })
}       
function binlist(res){
    let str = ''

    res.forEach((item,index) =>{
        str += `
         <li class=${index}>${item.title}</li>
        `

    })
    cateBox.innerHTML = str
}

getlist()
function getlist(){
    ajax({
        url:'http://chst.vip:1234/api/getbaicaijiaproduct?titleid=0',
        success(res){
            res = res.result
            all(res)
        }
    })

}
function all(res){
    let sar = ''
    res.forEach((item,index) => {
        sar += `
        <div class="box">
            <ul>
                <li>
                    <div class = "a">
                    <div class="img">${item.productImg}</div>
                    <div class="infor">
                    <h4>${item.productName}</h4>
                    <div class="price">
                    ${item.productPrice}
                    </div>
                            <div class="down">
                            ${item.productCouponRemain}
                                    <div class="bar-in">100%</div>
                                </div>
                                <span>已领126张/剩余0张</span>
                                <div class="click">
                                <div class="left">${item.productCoupon}</div>
                                <div class="right">${item.productHref}</div>
                            </div>
                        </div>
                       </div> 

                 </div>
                </li>
            </ul>
        </div>
        `
    })
    message.innerHTML = sar
}

cateBox.addEventListener('click',e =>{
    e = e || window.event;
    const target = e.target ;
    console.log(target.className);
    ajax({
            url:`http://chst.vip:1234/api/getbaicaijiaproduct?titleid=${target.className}`,
                success(res){
                 res = res.result;
                 console.log(res);
                 grtMessage(res)
            }
        })

})

 function grtMessage(res){
    let str = ''
    res.forEach((item,index) =>{
        str += `
        <div class="box">
            <ul>
                <li>
                    <div class = "a">
                    <div class="img">${item.productImg}</div>
                    <div class="infor">
                    <h4>${item.productName}</h4>
                    <div class="price">
                    ${item.productPrice}
                    </div>
                            <div class="down">
                            ${item.productCouponRemain}
                                    <div class="bar-in">100%</div>
                                </div>
                                <span>已领126张/剩余0张</span>
                                <div class="click">
                                <div class="left">${item.productCoupon}</div>
                                <div class="right">${item.productHref}</div>
                            </div>
                        </div>
                       </div> 

                 </div>
                </li>
            </ul>
        </div>
        `
    })
    message.innerHTML = str
}


})(window)